<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SQLColumn
 *
 * @author vlad
 */
class SQLColumn extends SQLStruct {
    
    private $_properties;
    private $_privileges;
    
    public function __construct($dbh, $columnParams) {
        $this->setDBHandle($dbh);
        if (!empty($columnParams) && is_array($columnParams)) {
            $this->_properties = $columnParams;
            $this->collectInformation();
        }
        return $this;
    }   
    
    private function collectInformation() {
        // | Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
        if (!empty($this->_properties['Field'])) {$this->_name = $this->_properties['Field'];}
        // print "\t\tCollecting information on column ".$this->_name."\n";
        if (!empty($this->_properties['Privileges'])) {
            $this->_privileges = explode(',', $this->_properties['Privileges']);
        }
        return $this;
    }
    
    public function GetProperties() {
        return $this->_properties;
    }


    public function __toString() {
        return $this->_name;
    }
    
    public function IsPrimaryKey() {
        return ($this->_properties['Key'] == "PRI");
    }
    
}

?>
